home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / lib2to3 / fixes / fix_renames.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  2.2 KB  |  53 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''Fix incompatible renames
  5.  
  6. Fixes:
  7.   * sys.maxint -> sys.maxsize
  8. '''
  9. from  import fixer_base
  10. from fixer_util import Name, attr_chain
  11. MAPPING = {
  12.     'sys': {
  13.         'maxint': 'maxsize' } }
  14. LOOKUP = { }
  15.  
  16. def alternates(members):
  17.     return '(' + '|'.join(map(repr, members)) + ')'
  18.  
  19.  
  20. def build_pattern():
  21.     for module, replace in MAPPING.items():
  22.         for old_attr, new_attr in replace.items():
  23.             LOOKUP[(module, old_attr)] = new_attr
  24.             yield "\n                  import_from< 'from' module_name=%r 'import'\n                      ( attr_name=%r | import_as_name< attr_name=%r 'as' any >) >\n                  " % (module, old_attr, old_attr)
  25.             yield "\n                  power< module_name=%r trailer< '.' attr_name=%r > any* >\n                  " % (module, old_attr)
  26.         
  27.     
  28.  
  29.  
  30. class FixRenames(fixer_base.BaseFix):
  31.     PATTERN = '|'.join(build_pattern())
  32.     order = 'pre'
  33.     
  34.     def match(self, node):
  35.         match = super(FixRenames, self).match
  36.         results = match(node)
  37.         if results:
  38.             if []([ match(obj) for obj in attr_chain(node, 'parent') ]):
  39.                 return False
  40.             return results
  41.         return False
  42.  
  43.     
  44.     def transform(self, node, results):
  45.         mod_name = results.get('module_name')
  46.         attr_name = results.get('attr_name')
  47.         if mod_name and attr_name:
  48.             new_attr = LOOKUP[(mod_name.value, attr_name.value)]
  49.             attr_name.replace(Name(new_attr, prefix = attr_name.get_prefix()))
  50.         
  51.  
  52.  
  53.